(function(window) {
	let Bird = window.Bird = function() {
		//随机小鸟样式
		this.birdNth = Math.round(Math.random() * 2)
		this.birdImg0 = myGame['bird'+this.birdNth+'_0']
		this.birdImg1 = myGame['bird'+this.birdNth+'_1']
		this.birdImg2 = myGame['bird'+this.birdNth+'_2']
		this.birdWidth = parseInt(myGame.c.height*0.08)			//小鸟自适应尺寸
		this.birdHeight = parseInt(this.birdImg0.height/this.birdImg0.width * this.birdWidth)		//小鸟自适应尺寸
		this.x = parseInt(myGame.c.width/2 - this.birdWidth/2)		//x坐标
		this.y = parseInt(myGame.c.height*0.2 + this.birdHeight)	//y坐标
		this.birdSprite = 0		//小鸟精灵图序号
		this.fno = 0			//小鸟自己的帧数，用于下落算法
		this.hasEnergy = false	//是否有能量（向上飞）
		this.d = 0				//小鸟旋转度数
	}
	
	//更新x坐标
	Bird.prototype.update = function () {
		if(!this.hasEnergy){	//下落，越来越快
			this.y += this.fno * myGame.birdDownSpeed
			//旋转
			this.d += 0.1
		}else{	//向上飞
			//帧速率（每多少毫秒1帧）- 小帧数
			this.y -= (16 - this.fno) * myGame.birdFlySpeed
			//当y-=为0或负数时继续掉落
			if(this.fno>16){
				this.hasEnergy = false
			}
			//旋转
			this.d -= 0.1
			this.d <= -0.5 && (this.d=-0.5)
		}
		this.fno++
		
		//小鸟飞(切换精灵图)
		myGame.fno % 10 || (this.birdSprite = myGame.fno % 3)
		
		//掉地上判断
		if(this.y+this.birdHeight >= myGame.bg.height){
			//切换到结束场景
			myGame.sceneManager.curScene = 3
		}
	}
	
	//渲染
	Bird.prototype.render = function () {
		//渲染
		myGame.ctx.save()	//旋转
		myGame.ctx.translate(this.x+this.birdWidth/2 , this.y+this.birdHeight/2)
		myGame.ctx.rotate(this.d)
		myGame.ctx.drawImage(this['birdImg'+this.birdSprite] , -this.birdWidth/2 , -this.birdHeight/2 ,this.birdWidth ,this.birdHeight)
		myGame.ctx.restore()
	}
})(window)